package threadtest;

public class TA implements Runnable {

	String content;
	Object outer;
	Object inner;
	static int sum = 10;

	public TA(String content, Object outer, Object inner) {
		super();
		this.content = content;
		this.outer = outer;
		this.inner = inner;
	}

	@Override
	public void run() {
		print("开始跑run方法");
		while (sum > 0) {
			synchronized (outer) {
				print("进入outer");
				synchronized (inner) {
					print("进入inner");
					System.err.println(Thread.currentThread().getName() + "---" + content + ":" + sum--);
					print("准备抽奖啦");
					inner.notify();
				}
				try {
					Thread.sleep(100);
				} catch (InterruptedException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				synchronized (inner) {
					print("您中奖啦！！！！！！！！！");
				}
				
				try {
					if (sum > 0) {
						print("开始wait");
						outer.wait();
						print("结束wait");
					}
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}

	private void print(String s) {
		System.err.println(Thread.currentThread().getName() + "---" + s);
	}

}
